
import jsPDF from 'jspdf';
import { IncidentItem } from '../types';
import { fonts } from './utils';

/**
 * Add the PDF header with title and metadata
 */
export const addHeader = (doc: jsPDF, incident: IncidentItem): number => {
  // Set initial y position
  let yPos = 15;
  
  // Add header with title
  doc.setFont(fonts.bold);
  doc.setFontSize(18);
  doc.setTextColor(0, 0, 0);
  doc.text('INCIDENT REPORT', 105, yPos, { align: 'center' });
  
  // Add incident title
  yPos += 8;
  doc.setFontSize(14);
  const title = incident.title || `Incident Report #${incident.id}`;
  doc.text(title, 105, yPos, { align: 'center' });
  
  // Add current date
  yPos += 8;
  doc.setFont(fonts.normal);
  doc.setFontSize(10);
  doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 105, yPos, { align: 'center' });
  
  // Add CheckCle logo or text
  yPos += 8;
  doc.setFontSize(12);
  doc.setFont(fonts.italic);
  doc.text('CheckCle Incident Management', 105, yPos, { align: 'center' });
  
  // Add horizontal line
  yPos += 5;
  doc.setLineWidth(0.5);
  doc.line(15, yPos, 195, yPos);
  
  // Return next Y position with some padding
  return yPos + 10;
};

/**
 * Add footer to all pages
 */
export const addFooter = (doc: jsPDF): void => {
  const pageCount = doc.getNumberOfPages();
  for (let i = 1; i <= pageCount; i++) {
    doc.setPage(i);
    doc.setFontSize(8);
    doc.setTextColor(100, 100, 100);
    doc.text(
      `Page ${i} of ${pageCount} | Generated by CheckCle Incident Management System`,
      105,
      285,
      { align: 'center' }
    );
  }
};

